package com.dragee.service.impl;

import com.dragee.entity.TextMsg;
import com.dragee.service.IMsg;
import com.thoughtworks.xstream.XStream;

import java.util.Date;

/**
 * @author tys on 9/18/20
 */
public class TextMsgImpl implements IMsg<TextMsg> {

    @Override
    public String messageToxml(TextMsg m) {
        XStream xstream  = new XStream();
        xstream.alias("xml", m.getClass());
        return xstream.toXML(m);
    }

    @Override
    public String initMessage(String FromUserName, String ToUserName, String content, String type) {
        TextMsg text = new TextMsg();
        text.setToUserName(FromUserName);
        text.setFromUserName(ToUserName);
        text.setContent(content);
        text.setCreateTime(new Date().getTime());
        text.setMsgType(type);
        return  this.messageToxml(text);
    }
}
